package com.heyqing.medium.day12;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * ClassName:MinDeletion
 * Package:com.heyqing.medium.day12
 * Description:
 *
 * @Date:2024/10/14
 * @Author:Heyqing
 */
public class MinDeletion {
    public int minDeletion(int[] nums) {
        if (nums.length == 0) return 0;
        Stack<Integer> stack = new Stack<>();
        stack.push(nums[0]);
        for (int i = 1; i < nums.length; i++) {
            Integer top = stack.peek();
            if (stack.size() % 2 == 0) {
                stack.add(nums[i]);
                continue;
            }
            if (top != nums[i]) {
                stack.add(nums[i]);
            }
        }
        int delete = nums.length - stack.size();
        if (stack.size() % 2 == 1) delete++;
        return delete;
    }
}
